
#ifndef __RSA_ENCRYPT_H
#define __RSA_ENCRYPT_H

#include "CryptoPipeBlock.h"
#include "../aprtools/APRBucketBrigade.h"
#include <openssl/rsa.h>
#include "RSAPublicKey.h"

/** Class encapsulating an interface to encryption with an RSA public
 * key. */
class RSAEncrypt : public CryptoPipeBlock
{
   public:
      RSAEncrypt(const RSAPublicKey &rsapubkey);
      RSAEncrypt(APRBucketBrigade &iinput, APRBucketBrigade &ioutput, const RSAPublicKey &rsapubkey);
      ~RSAEncrypt();
      // Encrypt data block and return encrypted data
      char *processDataBlock(const char *plainblock, apr_size_t plainsize, apr_size_t *codedsize);
      // Begin encryption of the data pipe
      int processPipeBegin();
      // Step through the encryption of the data pipe
      int processPipeStep();
      // Step through the data, recording data movement
      int processPipeStep(int *movementin, int *movementout);
      // End encryption of the data pipe
      int processPipeEnd();
      /** Was the process secure? */
      int processWasSecure() { return 1; }
   private:
      /** A copy of the RSA public key. */
      RSA *key;
      /** The input bucket brigade. As this is pointer to the outside,
       * it is not deleted in the destructor. */
      APRBucketBrigade *input;
      /** The output bucket brigade. As this is pointer to the
       * outside, it is not deleted in the destructor. */
      APRBucketBrigade *output;
      /** The previously encrypted block for CBC. */
      char *previous_block;
};

#endif
